What is StringIndexer , VectorIndexer, and how to use them

31

Dataset<Row> dataFrame = ... ;   
StringIndexerModel labelIndexer = new StringIndexer()
               .setInputCol("label")
               .setOutputCol("indexedLabel")
               .fit(dataFrame);

 VectorIndexerModel featureIndexer = new VectorIndexer()
               .setInputCol("s")
               .setOutputCol("indexedFeatures")
               .setMaxCategories(4)
               .fit(dataFrame);
IndexToString labelConverter = new IndexToString()
               .setInputCol("prediction")
               .setOutputCol("predictedLabel")
               .setLabels(labelIndexer.labels());

Comments

Submit
0 Comments